package com.msite

import com.msite.service.SysUserService
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.IntegrationTest
import org.springframework.boot.test.SpringApplicationConfiguration
import org.springframework.boot.test.TestRestTemplate
import org.springframework.http.ResponseEntity
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
import org.springframework.test.context.web.WebAppConfiguration
import org.springframework.web.client.RestTemplate
/**
 * Created by tpeng on 2015/11/25.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = MySiteApplication.class)
@WebAppConfiguration
@IntegrationTest(value = 'server.port=0')
class SpringBootTest {

    @Value('${local.server.port}')
    private int port;

    private URL base;

    private RestTemplate template;

    @Autowired
    SysUserService sysUserService;

    @Before
    public void setUp() throws Exception {
        this.base = new URL("http://localhost:" + port + "/sa/login_");
        println this.base
        template = new TestRestTemplate();
    }

    @Test
    public void getHello() throws Exception {
        ResponseEntity<String> response =
                template.getForEntity(base.toString(), String.class);
        //assertThat(response.getBody(), equalTo("Greetings from Spring Boot!"));
        println response.getBody()
    }

    @Test
    public void testMapper() throws Exception {
        /*SysUser user = sysUserService.getByUsername("admin");
        println user*/
    }
}
